/*
HOSPITAL CORPORATIZATION

THIS DO FILE IS THE MASTER FILE CONTAINING ALL SELF-WRITTEN PROGRAMS THAT DO OFTEN
REPEATED TASKS;

FIRST CREATED: MAY 18, 2022
LAST UPDATED: DEC 24, 2023

*/

/*********************************************************************************
SET INDICATOR FOR NON-DEFERRABLE ADMISSION;

FIRST CREATED: SEPT 16, 2022 FROM V1
LAST UPDATED: 

SEPT 16 2022: REORGANIZE THE NON-DEF CATEGORIES TO MATCH WHAT DOYLE ET AL HAD IN THEIR TABLE A1. CIRC, RESP, AND INJURY.

DEC 24, 2023: PREPARE FOR REPLICATION PACKAGE;
*/

cap program drop ident_nondef
program define ident_nondef

*set trace on
gen i_nondef=0
gen pdx =substr(prncpal_dgns_cd,1,3) 

gen i_circ = inlist(pdx,"410","I21")  | inlist(pdx,"431","433","434","435") | inlist(pdx,"I61","I63","I65","I66","I67","G45")

gen i_resp = inlist(pdx,"482","486","507","518") | inlist(pdx,"J14","J15","J18","J69","J95","J96","J98","J82","J81") | inlist(substr(prncpal_dgns_cd,1,4),"B448") | inlist(pdx,"J80") 

gen i_inj =  inrange(pdx,"807","824") | inlist(pdx,"959","965","969") | inrange(substr(prncpal_dgns_cd,1,4),"S222","S225") | inlist(pdx,"S32","S72","S82") | inlist(substr(prncpal_dgns_cd,1,4),"S128","S129") | inlist(pdx,"T14","S89","S09","S49","S59","S69","S79","S99","T07") | inlist(pdx,"S19","S29","T39","T40","T42","T43")

replace i_nondef = i_circ==1 | i_resp==1 | i_inj==1 
	
end
*end program;

